import React, {Component} from 'react';
import {View, BackHandler, StatusBar} from 'react-native';
import {isAndroid} from '../utils/utils';
import ModalDropdown from 'react-native-modal-dropdown';

export default class Dropdown extends Component {
	
	constructor(...args) {
		super(...args);
		this.show = this.show.bind(this);
		this.hide = this.hide.bind(this);
		this.select = this.select.bind(this);
	}
	
	show() {
		this.refs.md.show();
	}
	
	hide() {
		this.refs.md.hide();
	}
	
	select(idx) {
		this.refs.md.select(idx);
	}
	
  	render() {
        return (
        	<ModalDropdown 
        		ref='md'  
	        	disabled={this.props.disabled} 
	        	defaultIndex={this.props.defaultIndex} 
	        	defaultValue={this.props.defaultValue} 
	        	options={this.props.options} 
	        	animated={this.props.animated} 
	        	showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator} 
	        	style={this.props.style} 
	        	textStyle={this.props.textStyle} 
	        	dropdownStyle={this.props.dropdownStyle} 
	        	dropdownTextStyle={this.props.dropdownTextStyle} 
	        	dropdownTextHighlightStyle={this.props.dropdownTextHighlightStyle} 
	        	adjustFrame={(position) => {
	        		if(isAndroid()) {
	        			position.top = position.top - StatusBar.currentHeight;
	        		}
	        		if(this.props.adjustFrame) {
	        			position = this.props.adjustFrame(position);
	        		}
	        		return position;
	        	}}
	        	renderRow={this.props.renderRow || ((option, index, isSelected) => option)} 
	        	renderSeparator={this.props.renderSeparator} 
	        	renderButtonText={this.props.renderButtonText} 
	        	onDropdownWillShow={this.props.onDropdownWillShow} 
	        	onDropdownWillHide={this.props.onDropdownWillHide} 
	        	onSelect={this.props.onSelect} 
	        	accessible={this.props.accessible} 
	        	keyboardShouldPersistTaps={this.props.keyboardShouldPersistTaps} 
        	>
        		{this.props.children}
        	</ModalDropdown>
        );
	}
  	
}